//
//  KLRequest.h
//  KoalaUtilKit
//
//  Created by Tommy on 15/1/6.
//  Copyright (c) 2015年 Koala Team. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ReactiveCocoa.h"
#import "KLIRequest.h"
#import "KLITransformer.h"

@class KLRequest;
@protocol KLITransformer;


typedef void (^KLRequestBlock)(id<KLIRequest> request);


@interface KLRequest : NSOperation<KLIRequest>

@property(nonatomic,strong)NSError *error;
@property(nonatomic,assign)CGFloat progress;
@property(nonatomic,strong)id      response;
@property(nonatomic,copy)KLRequestBlock requestBlock;
@property(nonatomic,copy)id<KLITransformer> transformer;
@property(nonatomic,copy)NSDictionary *params;

/**
 *initial methods
 */
- (instancetype)initWithBlock:(KLRequestBlock)requestBlock;
- (instancetype)initWithParams:(NSDictionary*)params andTransformer:(id<KLITransformer>)transformer;
- (instancetype)initWithTransformer:(id<KLITransformer>)transformer andRequestBlock:(KLRequestBlock)requestBlock;
- (instancetype)initWithParams:(NSDictionary*)params andRequestBlock:(KLRequestBlock)requestBlock;
- (instancetype)initWithParams:(NSDictionary*)params withTransformer:(id<KLITransformer>)transformer andRequestBlock:(KLRequestBlock)requestBlock;

/**
 *will send response or error to subscribe
 */
- (RACSignal *) startRequest;
- (RACSignal *) restart;
- (void) cancel;

/**
 *please override the method,update error,progress and response if needed
 *
 */
- (void)doRequest;


- (void)setFinished:(BOOL)finished;
- (void)setExecuting:(BOOL)executing;

@end
